﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace PuzzleCoop
{
    public abstract class Skill
    {
        public static PlayScreen playScreen;
        public Player caster;
        protected int manaCost;
        protected int pointCost;
        protected int castTime;
        public bool isCasting = true;
        public bool alive = true;

        public Skill(Player caster)
        {
            playScreen = caster.playScreen;
            this.caster = caster;
            //this.manaCost = Def.MagicDefs[MagicNumber].ManaCost;
            this.castTime = 0;// Def.MagicDefs[MagicNumber].CastTime;
            if (caster == null || !caster.alive) { alive = false; return; }
            if (caster.isCasting) { Log.Add("Não pode castar outro skill enquanto estiver castando, sua mula!"); alive = false; return; }
            if (!caster.ConsumeMana(manaCost)) { Log.Add("Não tem mana suficiente, seu pobre!!!"); alive = false; return; } // se não tem mana suficiente, a mágica já morre
            caster.Cast(castTime);
        }

        public virtual void Update(GameTime gameTime)
        {
            if (!alive) return;
            if (!caster.alive) { alive = false; return; }
            if (isCasting) Casting(gameTime);
            else Effect(gameTime);
        }

        public virtual void Casting(GameTime gameTime)
        {
            caster.castTimer += gameTime.ElapsedGameTime.TotalMilliseconds;
            if (caster.castTimer > caster.castTime)
            {
                caster.castTimer = 1;
                isCasting = caster.isCasting = false;
            }
        }

        public abstract void Effect(GameTime gameTime);
    }


}
